package com.fs.chatx.module.chat.api;

import com.alibaba.fastjson.JSONArray;
import com.fs.chatx.core.api.R;
import com.fs.chatx.module.chat.service.DeepseekService;
import io.github.pigmesh.ai.deepseek.core.chat.ChatCompletionResponse;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@Slf4j
@RestController
@RequestMapping("/api")
public class DeepSeekController
{

    @Autowired
    private DeepseekService deepseekService;



    @GetMapping(value ="/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<ChatCompletionResponse> chat(String prompt)
    {
        return deepseekService.chat(prompt);
    }

    @PostMapping(value = "/chat/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<ChatCompletionResponse> chatAdvanced(String prompt)
    {
        return deepseekService.chatAdvanced(prompt);
    }

    //联网搜素
    @GetMapping(value = "/chatSearch", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<ChatCompletionResponse> chatSearch(String prompt)
    {
        return deepseekService.chatSearch(prompt);
    }


    @GetMapping(value = "/ragSearch", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<ChatCompletionResponse> ragSearch( String prompt)
    {
         return deepseekService.ragSearch(prompt);
    }


    @GetMapping(value = "/structCheckReport")
    public R structCheckReport(String prompt)
    {
        if(StringUtils.isEmpty(prompt)){
            return R.success();
        }
        return R.success(deepseekService.structCheckReport(prompt)) ;
    }


}
